<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='lb' /></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">

            <div class="layui-form-item">
                <form name="totalForm" id="totalForm" action="${web_domain}/supplier/goods/brand/list" method="get">

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='ppmc' /></label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" placeholder="<fmt:message key='qsrppmc' />" value="<c:if test='${params.name !=null}'>${params.name}</c:if>" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-sm layuiadmin-btn-list" id="search"><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> 搜索</button>
                    </div>
                </form>
            </div>
        </div>

    </div>

    <div class="layui-card">
        <div class="layui-field-box layui-form">
            <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-normal" id="add"><i class="layui-icon">&#xe61f;</i> 添加品牌</a>
            <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-warm" id="putaways"><i class="layui-icon">&#xe605;</i> 批量申请上架</a>

            <table class="layui-table" lay-size="sm">
                <thead>
                <th width="5%"><input id="checkboxs" type="checkbox" value="${item.id}" lay-ignore lay-skin="primary"/></th>
                <th width="15%"><fmt:message key='ppmc' /></th>
                <th width="15%"><fmt:message key='pplg' /></th>
                <th width="50%"><fmt:message key='ppms' /></th>
                <th width="10%"><fmt:message key='zt' /></th>
                <th width="10%"><fmt:message key='cz' /></th>

                </thead>
                <c:forEach items="${page.result}" var="item" varStatus="status">
                    <tr>
                        <td><input type="checkbox" value="${item.id}" class="feijin-check" lay-ignore lay-skin="primary"/></td>
                        <td>${item.name }</td>
                        <td><img src="${store_domain}/uploads/${item.logo }" class="preview" style="width:40px;height:40px;"/></td>
                        <td>${item.note }</td>
                        <td>
                            <c:choose>
                                <c:when test="${item.status eq 1}"><fmt:message key='dshenh' /></c:when>
                                <c:when test="${item.status eq 2}"><fmt:message key='shz' /></c:when>
                                <c:when test="${item.status eq 3}"><fmt:message key='shtg' /></c:when>
                                <c:when test="${item.status eq 4}"><fmt:message key='shbtg' /></c:when>
                            </c:choose>
                        </td>
                        <td>
                            <div class="layui-btn-container">
                                <c:choose>
                                    <c:when test="${(item.status eq 1 || item.status eq 4) && item.merchant.id == CURRENT_USER.id}">
                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs feijin-apply-putaway"><fmt:message key='tjsh' /></a>
                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-remove"><fmt:message key='sc' /></a>
                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-modify"><fmt:message key='bj' /></a>
                                    </c:when>
                                </c:choose>

                            </div>
                        </td>
                    </tr>
                </c:forEach>
            </table>
            <jsp:include page="/commons/page.jsp" flush="true"/>
        </div>
    </div>

</div>

<script>

    $(function () {

        //全选反选
        $("#checkboxs").click(function () {
            if (this.checked) {
                $(".feijin-check:checkbox").prop("checked", true);
            } else {
                $(".feijin-check:checkbox").prop("checked", false);
            }
        });

        //批量申请上架
        $("#putaways").click(function () {
            var ids = [];

            $(".feijin-check:checkbox:checked").each(function (index, item) {
                var id = $(item).val();
                ids.push(id);
            });

            if (ids.length == 0) {
                layer.msg('<fmt:message key='qxgxxyczdjl' />');
                return false;
            }

            layer.open({
                content: '<fmt:message key='qrtjppsqm' />？'
                , btn: ['<fmt:message key='sqsj' />', '<fmt:message key='qx' />']
                , yes: function (index, layero) {
                    $.ajax({
                        url: "${web_domain}/supplier/goods/brand/applysPutaway",
                        type: "post",
                        dataType: "json",
                        data: {
                            "ids": ids.join(";"),
                            "_method": "put"
                        },
                        success: function (result) {
                            if (result.status) {
                                location.reload();
                            }
                        }
                    });
                }
            });
        });

        //申请上架品牌
        $(".feijin-apply-putaway").click(function () {
            var id = $(this).attr("data-id");
            layer.confirm("<fmt:message key='qrtjsjgppm' />?", function () {
                feijin.put({
                    url: "${web_domain}/supplier/goods/brand/applyPutaway",
                    data: {id: id}
                });
            });
        });

        $("#add").click(function () {
            layer.open({
                type: 2
                , title: '<fmt:message key='tjpp' />'
                , content: '${web_domain}/supplier/goods/brand/create'
                , maxmin: true
                , area: ['80%', '80%']
                , btn: ['<fmt:message key='qd' />', '<fmt:message key='qx' />']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });

        //编辑
        $(".feijin-modify").click(function () {

            var id = $(this).attr("data-id");

            layer.open({
                type: 2
                , title: '<fmt:message key='bjpp' />'
                , content: '${web_domain}/supplier/goods/brand/' + id + '/modify'
                , maxmin: true
                , area: ['80%', '80%']
                , btn: ['<fmt:message key='qd' />', '<fmt:message key='qx' />']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });


        //删除品牌
        $(".feijin-remove").click(function () {
            var id = $(this).attr("data-id");
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 0,
                    title: '<fmt:message key='scpp' />',
                    border: [0],
                    content: '<span class="orange"><fmt:message key='qrscppm' /></span>',
                    btn: ['<fmt:message key='sc' />', '<fmt:message key='qx' />'],
                    yes: function () {
                        $.ajax({
                            type: "post",
                            url: "${web_domain}/supplier/goods/brand/remove",
                            dataType: "json",
                            data: {
                                "id": id,
                                "_method": "delete"
                            },
                            success: function (data) {
                                if (data.status) {
                                    location.reload();
                                } else {
                                    layui.use('layer', function () {
                                        layer.msg(data.message);
                                    });
                                }

                            }
                        });
                    },
                    no: function () {
                        layer.close(index);
                    }
                });
            });
        });


    });
</script>
</body>
</fmt:bundle></html>
